<template>
  <Form class="login_form" ref="loginForm" :model="form" :rules="rules" @keydown.enter.native="handleSubmit">
    <FormItem class="formitem" prop="userName">
      <Input class="input" size="large" v-model="form.userName" placeholder="请输入用户名">
        <span slot="prepend">
          <Icon :size="16" type="ios-person"></Icon>
        </span>
      </Input>
    </FormItem>
    <FormItem class="formitem"  prop="password">
      <Input class="input" size="large" type="password" v-model="form.password" placeholder="请输入密码">
        <span slot="prepend">
          <Icon :size="14" type="md-lock"></Icon>
        </span>
      </Input>
    </FormItem>
    <FormItem class="formitem">
      <Button class="loginbutton" @click="handleSubmit" type="primary" long>登录</Button>
    </FormItem>
  </Form>
</template>
<script>
export default {
  name: 'LoginForm',
  props: {
    userNameRules: {
      type: Array,
      default: () => {
        return [
          { required: true, message: '账号不能为空', trigger: 'blur' }
        ]
      }
    },
    passwordRules: {
      type: Array,
      default: () => {
        return [
          { required: true, message: '密码不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  data () {
    return {
      form: {
        userName: '',
        password: ''
      }
    }
  },
  computed: {
    rules () {
      return {
        userName: this.userNameRules,
        password: this.passwordRules
      }
    }
  },
  methods: {
    handleSubmit () {
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          this.$emit('on-success-valid', {
            userName: this.form.userName,
            password: this.form.password
          })
        }
      })
    }
  }
}
</script>

<style lang="less">
.login_form{
    height: 100%;
}
.loginbutton{
      background: url("../../../assets/button2.png");
      background-size:100% 100%;
      border:none;
      color:#fff;
      height: 50px;
    }
.loginbutton:hover {
background: url("../../../assets/buttonhover.png");
background-size:100% 100%;
border:none;
color:#fff;
}
.formitem{
  height: 30%;
  padding-top: 20px;
  margin-bottom: 0px !important;
}
.ivu-form-item-content{
  height:45px;
}
/*
.login_form .ivu-input{
  color: #515a6e !important;
  border: 1px solid #dcdee2 !important;
  background-color: #fff !important;
}*/
</style>
